From: Florian Müllner Date: Fri, 26 Jul 2019 19:00:06 +0000 (+0200) Subject: shell: Rename GLSLQuad to GLSLEffect X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~839^2^2~101 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=99a2fad311cb5e29814d32a577331397f7d26fe0;p=gnome-shell.git shell: Rename GLSLQuad to GLSLEffect You can guess where this is going ... https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/651 --- diff --git a/src/meson.build b/src/meson.build index 97a5a796c..7129c5ac1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -86,7 +86,7 @@ libshell_public_headers = [ 'shell-app-system.h', 'shell-app-usage.h', 'shell-embedded-window.h', - 'shell-glsl-quad.h', + 'shell-glsl-effect.h', 'shell-gtk-embed.h', 'shell-global.h', 'shell-invert-lightness-effect.h', @@ -122,7 +122,7 @@ libshell_sources = [ 'shell-embedded-window.c', 'shell-embedded-window-private.h', 'shell-global.c', - 'shell-glsl-quad.c', + 'shell-glsl-effect.c', 'shell-gtk-embed.c', 'shell-invert-lightness-effect.c', 'shell-keyring-prompt.c', diff --git a/src/shell-glsl-effect.c b/src/shell-glsl-effect.c new file mode 100644 index 000000000..9274b58de --- /dev/null +++ b/src/shell-glsl-effect.c @@ -0,0 +1,203 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/** + * SECTION:shell-glsl-quad + * @short_description: Draw a rectangle using GLSL + * + * A #ShellGLSLQuad draws one single rectangle, sized to the allocation + * box, but allows running custom GLSL to the vertex and fragment + * stages of the graphic pipeline. + * + * To ease writing the shader, a single texture layer is also used. + */ + +#include "config.h" + +#include +#include "shell-glsl-effect.h" + +typedef struct _ShellGLSLQuadPrivate ShellGLSLQuadPrivate; +struct _ShellGLSLQuadPrivate +{ + CoglPipeline *pipeline; +}; + +G_DEFINE_TYPE_WITH_PRIVATE (ShellGLSLQuad, shell_glsl_quad, CLUTTER_TYPE_ACTOR); + +static gboolean +shell_glsl_quad_get_paint_volume (ClutterActor *actor, + ClutterPaintVolume *volume) +{ + return clutter_paint_volume_set_from_allocation (volume, actor); +} + +static void +shell_glsl_quad_paint (ClutterActor *actor) +{ + ShellGLSLQuad *self = SHELL_GLSL_QUAD (actor); + ShellGLSLQuadPrivate *priv; + guint8 paint_opacity; + ClutterActorBox box; + + priv = shell_glsl_quad_get_instance_private (self); + + paint_opacity = clutter_actor_get_paint_opacity (actor); + clutter_actor_get_allocation_box (actor, &box); + + cogl_pipeline_set_color4ub (priv->pipeline, + paint_opacity, + paint_opacity, + paint_opacity, + paint_opacity); + cogl_framebuffer_draw_rectangle (cogl_get_draw_framebuffer (), + priv->pipeline, + box.x1, box.y1, + box.x2, box.y2); +} + + +/** + * shell_glsl_quad_add_glsl_snippet: + * @quad: a #ShellGLSLQuad + * @hook: where to insert the code + * @declarations: GLSL declarations + * @code: GLSL code + * @is_replace: wheter Cogl code should be replaced by the custom shader + * + * Adds a GLSL snippet to the pipeline used for drawing the actor texture. + * See #CoglSnippet for details. + * + * This is only valid inside the a call to the build_pipeline() virtual + * function. + */ +void +shell_glsl_quad_add_glsl_snippet (ShellGLSLQuad *quad, + ShellSnippetHook hook, + const char *declarations, + const char *code, + gboolean is_replace) +{ + ShellGLSLQuadClass *klass = SHELL_GLSL_QUAD_GET_CLASS (quad); + CoglSnippet *snippet; + + g_return_if_fail (klass->base_pipeline != NULL); + + if (is_replace) + { + snippet = cogl_snippet_new ((CoglSnippetHook)hook, declarations, NULL); + cogl_snippet_set_replace (snippet, code); + } + else + { + snippet = cogl_snippet_new ((CoglSnippetHook)hook, declarations, code); + } + + if (hook == SHELL_SNIPPET_HOOK_VERTEX || + hook == SHELL_SNIPPET_HOOK_FRAGMENT) + cogl_pipeline_add_snippet (klass->base_pipeline, snippet); + else + cogl_pipeline_add_layer_snippet (klass->base_pipeline, 0, snippet); + + cogl_object_unref (snippet); +} + +static void +shell_glsl_quad_dispose (GObject *gobject) +{ + ShellGLSLQuad *self = SHELL_GLSL_QUAD (gobject); + ShellGLSLQuadPrivate *priv; + + priv = shell_glsl_quad_get_instance_private (self); + + g_clear_pointer (&priv->pipeline, cogl_object_unref); + + G_OBJECT_CLASS (shell_glsl_quad_parent_class)->dispose (gobject); +} + +static void +shell_glsl_quad_init (ShellGLSLQuad *quad) +{ +} + +static void +shell_glsl_quad_constructed (GObject *object) +{ + ShellGLSLQuad *self; + ShellGLSLQuadClass *klass; + ShellGLSLQuadPrivate *priv; + CoglContext *ctx = + clutter_backend_get_cogl_context (clutter_get_default_backend ()); + + G_OBJECT_CLASS (shell_glsl_quad_parent_class)->constructed (object); + + /* Note that, differently from ClutterBlurEffect, we are calling + this inside constructed, not init, so klass points to the most-derived + GTypeClass, not ShellGLSLQuadClass. + */ + klass = SHELL_GLSL_QUAD_GET_CLASS (object); + self = SHELL_GLSL_QUAD (object); + priv = shell_glsl_quad_get_instance_private (self); + + if (G_UNLIKELY (klass->base_pipeline == NULL)) + { + klass->base_pipeline = cogl_pipeline_new (ctx); + cogl_pipeline_set_blend (klass->base_pipeline, "RGBA = ADD (SRC_COLOR * (SRC_COLOR[A]), DST_COLOR * (1-SRC_COLOR[A]))", NULL); + + if (klass->build_pipeline != NULL) + klass->build_pipeline (self); + } + + priv->pipeline = cogl_pipeline_copy (klass->base_pipeline); + + cogl_pipeline_set_layer_null_texture (priv->pipeline, 0); +} + +static void +shell_glsl_quad_class_init (ShellGLSLQuadClass *klass) +{ + ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->constructed = shell_glsl_quad_constructed; + gobject_class->dispose = shell_glsl_quad_dispose; + + actor_class->get_paint_volume = shell_glsl_quad_get_paint_volume; + actor_class->paint = shell_glsl_quad_paint; +} + +/** + * shell_glsl_quad_get_uniform_location: + * @quad: a #ShellGLSLQuad + * @name: the uniform name + * + * Returns: the location of the uniform named @name, that can be + * passed to shell_glsl_quad_set_uniform_float(). + */ +int +shell_glsl_quad_get_uniform_location (ShellGLSLQuad *quad, + const char *name) +{ + ShellGLSLQuadPrivate *priv = shell_glsl_quad_get_instance_private (quad); + return cogl_pipeline_get_uniform_location (priv->pipeline, name); +} + +/** + * shell_glsl_quad_set_uniform_float: + * @quad: a #ShellGLSLQuad + * @uniform: the uniform location (as returned by shell_glsl_quad_get_uniform_location()) + * @n_components: the number of components in the uniform (eg. 3 for a vec3) + * @total_count: the total number of floats in @value + * @value: (array length=total_count): the array of floats to set @uniform + */ +void +shell_glsl_quad_set_uniform_float (ShellGLSLQuad *quad, + int uniform, + int n_components, + int total_count, + const float *value) +{ + ShellGLSLQuadPrivate *priv = shell_glsl_quad_get_instance_private (quad); + cogl_pipeline_set_uniform_float (priv->pipeline, uniform, + n_components, total_count / n_components, + value); +} diff --git a/src/shell-glsl-effect.h b/src/shell-glsl-effect.h new file mode 100644 index 000000000..da2c480dd --- /dev/null +++ b/src/shell-glsl-effect.h @@ -0,0 +1,56 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +#ifndef __SHELL_GLSL_QUAD_H__ +#define __SHELL_GLSL_QUAD_H__ + +#include "st.h" +#include + +/** + * ShellSnippetHook: + * Temporary hack to work around Cogl not exporting CoglSnippetHook in + * the 1.0 API. Don't use. + */ +typedef enum { + /* Per pipeline vertex hooks */ + SHELL_SNIPPET_HOOK_VERTEX = 0, + SHELL_SNIPPET_HOOK_VERTEX_TRANSFORM, + + /* Per pipeline fragment hooks */ + SHELL_SNIPPET_HOOK_FRAGMENT = 2048, + + /* Per layer vertex hooks */ + SHELL_SNIPPET_HOOK_TEXTURE_COORD_TRANSFORM = 4096, + + /* Per layer fragment hooks */ + SHELL_SNIPPET_HOOK_LAYER_FRAGMENT = 6144, + SHELL_SNIPPET_HOOK_TEXTURE_LOOKUP +} ShellSnippetHook; + +#define SHELL_TYPE_GLSL_QUAD (shell_glsl_quad_get_type ()) +G_DECLARE_DERIVABLE_TYPE (ShellGLSLQuad, shell_glsl_quad, + SHELL, GLSL_QUAD, ClutterActor) + +struct _ShellGLSLQuadClass +{ + ClutterActorClass parent_class; + + CoglPipeline *base_pipeline; + + void (*build_pipeline) (ShellGLSLQuad *effect); +}; + +void shell_glsl_quad_add_glsl_snippet (ShellGLSLQuad *quad, + ShellSnippetHook hook, + const char *declarations, + const char *code, + gboolean is_replace); + +int shell_glsl_quad_get_uniform_location (ShellGLSLQuad *quad, + const char *name); +void shell_glsl_quad_set_uniform_float (ShellGLSLQuad *quad, + int uniform, + int n_components, + int total_count, + const float *value); + +#endif /* __SHELL_GLSL_QUAD_H__ */ diff --git a/src/shell-glsl-quad.c b/src/shell-glsl-quad.c deleted file mode 100644 index 1b543c09a..000000000 --- a/src/shell-glsl-quad.c +++ /dev/null @@ -1,203 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/** - * SECTION:shell-glsl-quad - * @short_description: Draw a rectangle using GLSL - * - * A #ShellGLSLQuad draws one single rectangle, sized to the allocation - * box, but allows running custom GLSL to the vertex and fragment - * stages of the graphic pipeline. - * - * To ease writing the shader, a single texture layer is also used. - */ - -#include "config.h" - -#include -#include "shell-glsl-quad.h" - -typedef struct _ShellGLSLQuadPrivate ShellGLSLQuadPrivate; -struct _ShellGLSLQuadPrivate -{ - CoglPipeline *pipeline; -}; - -G_DEFINE_TYPE_WITH_PRIVATE (ShellGLSLQuad, shell_glsl_quad, CLUTTER_TYPE_ACTOR); - -static gboolean -shell_glsl_quad_get_paint_volume (ClutterActor *actor, - ClutterPaintVolume *volume) -{ - return clutter_paint_volume_set_from_allocation (volume, actor); -} - -static void -shell_glsl_quad_paint (ClutterActor *actor) -{ - ShellGLSLQuad *self = SHELL_GLSL_QUAD (actor); - ShellGLSLQuadPrivate *priv; - guint8 paint_opacity; - ClutterActorBox box; - - priv = shell_glsl_quad_get_instance_private (self); - - paint_opacity = clutter_actor_get_paint_opacity (actor); - clutter_actor_get_allocation_box (actor, &box); - - cogl_pipeline_set_color4ub (priv->pipeline, - paint_opacity, - paint_opacity, - paint_opacity, - paint_opacity); - cogl_framebuffer_draw_rectangle (cogl_get_draw_framebuffer (), - priv->pipeline, - box.x1, box.y1, - box.x2, box.y2); -} - - -/** - * shell_glsl_quad_add_glsl_snippet: - * @quad: a #ShellGLSLQuad - * @hook: where to insert the code - * @declarations: GLSL declarations - * @code: GLSL code - * @is_replace: wheter Cogl code should be replaced by the custom shader - * - * Adds a GLSL snippet to the pipeline used for drawing the actor texture. - * See #CoglSnippet for details. - * - * This is only valid inside the a call to the build_pipeline() virtual - * function. - */ -void -shell_glsl_quad_add_glsl_snippet (ShellGLSLQuad *quad, - ShellSnippetHook hook, - const char *declarations, - const char *code, - gboolean is_replace) -{ - ShellGLSLQuadClass *klass = SHELL_GLSL_QUAD_GET_CLASS (quad); - CoglSnippet *snippet; - - g_return_if_fail (klass->base_pipeline != NULL); - - if (is_replace) - { - snippet = cogl_snippet_new ((CoglSnippetHook)hook, declarations, NULL); - cogl_snippet_set_replace (snippet, code); - } - else - { - snippet = cogl_snippet_new ((CoglSnippetHook)hook, declarations, code); - } - - if (hook == SHELL_SNIPPET_HOOK_VERTEX || - hook == SHELL_SNIPPET_HOOK_FRAGMENT) - cogl_pipeline_add_snippet (klass->base_pipeline, snippet); - else - cogl_pipeline_add_layer_snippet (klass->base_pipeline, 0, snippet); - - cogl_object_unref (snippet); -} - -static void -shell_glsl_quad_dispose (GObject *gobject) -{ - ShellGLSLQuad *self = SHELL_GLSL_QUAD (gobject); - ShellGLSLQuadPrivate *priv; - - priv = shell_glsl_quad_get_instance_private (self); - - g_clear_pointer (&priv->pipeline, cogl_object_unref); - - G_OBJECT_CLASS (shell_glsl_quad_parent_class)->dispose (gobject); -} - -static void -shell_glsl_quad_init (ShellGLSLQuad *quad) -{ -} - -static void -shell_glsl_quad_constructed (GObject *object) -{ - ShellGLSLQuad *self; - ShellGLSLQuadClass *klass; - ShellGLSLQuadPrivate *priv; - CoglContext *ctx = - clutter_backend_get_cogl_context (clutter_get_default_backend ()); - - G_OBJECT_CLASS (shell_glsl_quad_parent_class)->constructed (object); - - /* Note that, differently from ClutterBlurEffect, we are calling - this inside constructed, not init, so klass points to the most-derived - GTypeClass, not ShellGLSLQuadClass. - */ - klass = SHELL_GLSL_QUAD_GET_CLASS (object); - self = SHELL_GLSL_QUAD (object); - priv = shell_glsl_quad_get_instance_private (self); - - if (G_UNLIKELY (klass->base_pipeline == NULL)) - { - klass->base_pipeline = cogl_pipeline_new (ctx); - cogl_pipeline_set_blend (klass->base_pipeline, "RGBA = ADD (SRC_COLOR * (SRC_COLOR[A]), DST_COLOR * (1-SRC_COLOR[A]))", NULL); - - if (klass->build_pipeline != NULL) - klass->build_pipeline (self); - } - - priv->pipeline = cogl_pipeline_copy (klass->base_pipeline); - - cogl_pipeline_set_layer_null_texture (priv->pipeline, 0); -} - -static void -shell_glsl_quad_class_init (ShellGLSLQuadClass *klass) -{ - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->constructed = shell_glsl_quad_constructed; - gobject_class->dispose = shell_glsl_quad_dispose; - - actor_class->get_paint_volume = shell_glsl_quad_get_paint_volume; - actor_class->paint = shell_glsl_quad_paint; -} - -/** - * shell_glsl_quad_get_uniform_location: - * @quad: a #ShellGLSLQuad - * @name: the uniform name - * - * Returns: the location of the uniform named @name, that can be - * passed to shell_glsl_quad_set_uniform_float(). - */ -int -shell_glsl_quad_get_uniform_location (ShellGLSLQuad *quad, - const char *name) -{ - ShellGLSLQuadPrivate *priv = shell_glsl_quad_get_instance_private (quad); - return cogl_pipeline_get_uniform_location (priv->pipeline, name); -} - -/** - * shell_glsl_quad_set_uniform_float: - * @quad: a #ShellGLSLQuad - * @uniform: the uniform location (as returned by shell_glsl_quad_get_uniform_location()) - * @n_components: the number of components in the uniform (eg. 3 for a vec3) - * @total_count: the total number of floats in @value - * @value: (array length=total_count): the array of floats to set @uniform - */ -void -shell_glsl_quad_set_uniform_float (ShellGLSLQuad *quad, - int uniform, - int n_components, - int total_count, - const float *value) -{ - ShellGLSLQuadPrivate *priv = shell_glsl_quad_get_instance_private (quad); - cogl_pipeline_set_uniform_float (priv->pipeline, uniform, - n_components, total_count / n_components, - value); -} diff --git a/src/shell-glsl-quad.h b/src/shell-glsl-quad.h deleted file mode 100644 index da2c480dd..000000000 --- a/src/shell-glsl-quad.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -#ifndef __SHELL_GLSL_QUAD_H__ -#define __SHELL_GLSL_QUAD_H__ - -#include "st.h" -#include - -/** - * ShellSnippetHook: - * Temporary hack to work around Cogl not exporting CoglSnippetHook in - * the 1.0 API. Don't use. - */ -typedef enum { - /* Per pipeline vertex hooks */ - SHELL_SNIPPET_HOOK_VERTEX = 0, - SHELL_SNIPPET_HOOK_VERTEX_TRANSFORM, - - /* Per pipeline fragment hooks */ - SHELL_SNIPPET_HOOK_FRAGMENT = 2048, - - /* Per layer vertex hooks */ - SHELL_SNIPPET_HOOK_TEXTURE_COORD_TRANSFORM = 4096, - - /* Per layer fragment hooks */ - SHELL_SNIPPET_HOOK_LAYER_FRAGMENT = 6144, - SHELL_SNIPPET_HOOK_TEXTURE_LOOKUP -} ShellSnippetHook; - -#define SHELL_TYPE_GLSL_QUAD (shell_glsl_quad_get_type ()) -G_DECLARE_DERIVABLE_TYPE (ShellGLSLQuad, shell_glsl_quad, - SHELL, GLSL_QUAD, ClutterActor) - -struct _ShellGLSLQuadClass -{ - ClutterActorClass parent_class; - - CoglPipeline *base_pipeline; - - void (*build_pipeline) (ShellGLSLQuad *effect); -}; - -void shell_glsl_quad_add_glsl_snippet (ShellGLSLQuad *quad, - ShellSnippetHook hook, - const char *declarations, - const char *code, - gboolean is_replace); - -int shell_glsl_quad_get_uniform_location (ShellGLSLQuad *quad, - const char *name); -void shell_glsl_quad_set_uniform_float (ShellGLSLQuad *quad, - int uniform, - int n_components, - int total_count, - const float *value); - -#endif /* __SHELL_GLSL_QUAD_H__ */